using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;

/// <summary>
/// AKS 2.0 - HiSoftware Inc.
/// 
/// SA DESIGN:
/// Robert B. Yonaitis 
/// </summary>

/// <variables>
/// oOutput          -  An object used in outputting the finalized code
/// sOutputBuilder   -  A string containing the code to be rendered to the page
/// oWriter          -  An object used to output the rendered code
/// sSearchString    -  A string used to store the string being used to locate the correct control to alter
/// </variables>

namespace AKSAdapters
{
	public class AKS_DateFilter_SmartAdapter : System.Web.UI.Adapters.ControlAdapter
	{
		public AKS_DateFilter_SmartAdapter()
		{

		}

		protected override void Render(HtmlTextWriter oOutput)
		{
			//Initializes sOutputBuilder as a new StringBuilder object
			StringBuilder sOutputBuilder = new StringBuilder();
			HtmlTextWriter oWriter = new HtmlTextWriter(new StringWriter(sOutputBuilder));
			base.Render(oWriter);

			//Initialize sSearchString
			string sSearchString = null;

			//Assign sSearchString to the string used to identify the correct control
			sSearchString = "style=\"display:none\"> Date</label>";
			//Removes the "style="display:none" thus enabling Sharepoint's hidden label for this control.
			sOutputBuilder.Replace(sSearchString, "> Date</label>");

			//Assign sSearchString to the string used to identify the correct control
			sSearchString = "title=\"Select a date from the calendar.\"></IFRAME>";
			//Adds an IFRAME element to the date filter IFRAME
			sOutputBuilder.Replace(sSearchString, "title=\"Select a date from the calendar.\">The Date Picker requires IFRAME support, please ask your System Administrator for help.</IFRAME>");

			//Output sOutputBuilder to be rendered
			oOutput.Write(sOutputBuilder.ToString());
		}
	}
}